package mirkofrancuski.battleship.db;

import java.util.Calendar;

public class HighScoreInfo {
	private int m_id;

	private int m_rank;
	private String m_playerName;
	private String m_adversaryName;
	private int m_numberOfMoves;
	
	private long m_time;

	public HighScoreInfo() {
		m_rank = 0;
		m_numberOfMoves = 0;
	}

	public HighScoreInfo(String playerName, String adversaryName,
			int numberOfMoves) {
		m_time = Calendar.getInstance().getTimeInMillis();

		m_playerName = playerName;
		m_adversaryName = adversaryName;
		m_numberOfMoves = numberOfMoves;

		m_id = this.hashCode();
	}

	public HighScoreInfo(int id, int rank, String playerName,
			String adversaryName, int numberOfMoves) {
		m_id = id;
		m_rank = rank;
		m_playerName = playerName;
		m_adversaryName = adversaryName;
		m_numberOfMoves = numberOfMoves;
	}

	public int getId() {
		return m_id;
	}

	public void setId(int id) {
		this.m_id = id;
	}

	public int getRank() {
		return m_rank;
	}

	public void setRank(int rank) {
		this.m_rank = rank;
	}

	public String getPlayerName() {
		return m_playerName;
	}

	public void setPlayerName(String playerName) {
		this.m_playerName = playerName;
	}

	public String getAdversaryName() {
		return m_adversaryName;
	}

	public void setAdversaryName(String adversaryName) {
		this.m_adversaryName = adversaryName;
	}

	public int getNumberOfMoves() {
		return m_numberOfMoves;
	}

	public void setNumberOfMoves(int numberOfMoves) {
		this.m_numberOfMoves = numberOfMoves;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((m_adversaryName == null) ? 0 : m_adversaryName.hashCode());
		result = prime * result + m_numberOfMoves;
		result = prime * result
				+ ((m_playerName == null) ? 0 : m_playerName.hashCode());
		result = prime * result + (int) (m_time ^ (m_time >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HighScoreInfo other = (HighScoreInfo) obj;
		if (m_adversaryName == null) {
			if (other.m_adversaryName != null)
				return false;
		} else if (!m_adversaryName.equals(other.m_adversaryName))
			return false;
		if (m_numberOfMoves != other.m_numberOfMoves)
			return false;
		if (m_playerName == null) {
			if (other.m_playerName != null)
				return false;
		} else if (!m_playerName.equals(other.m_playerName))
			return false;
		if (m_time != other.m_time)
			return false;
		return true;
	}
	
	@Override
	public String toString() {
		return "\n(" + m_id + ", " + m_rank
				+ ", " + m_playerName + ", "
				+ m_adversaryName + ", " + m_numberOfMoves
				+ ")";
	}

}
